package com.atguigu.feign.Controller;

import com.atguigu.feign.service.FeignService;
import com.atguigu.springcloud.entity.CommonResult;
import com.atguigu.springcloud.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/consumer")
public class FeignController {

    @Resource
    private FeignService FeignService;

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/feign/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        return FeignService.getPaymentById(id);
    }

    /**
     * 模拟feign超时请求
     *
     * feign客户端默认超时时间是1秒，超时就出现异常。
     * @return
     */
    @GetMapping("/feign/payment/feign/timeout")
    public String paymentFeignTimeout(){
        System.out.println("*-*--*");
        return FeignService.paymentFeignTimeout();
    }
}
